﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Aliyun.OSS;
using Aliyun.OSS.Common;

namespace SheXiangTou.Services
{
    public class OssService
    {
        static readonly string endpoint = ConfigerService.endpoint;// "oss-cn-beijing.aliyuncs.com";
        static readonly string accessKeyId = ConfigerService.accessKeyId;// "LTAI4GDvvfHZdxuXjd1R6C9W";
        static readonly string accessKeySecret = ConfigerService.accessKeySecret;// "OIXbiobj3z349naqfbomZdPw2HIkiX";
        static readonly string bucketName = ConfigerService.bucketName;// "zkzlgate";
        static readonly string objectName = ConfigerService.objectName;// "people/";

        static readonly OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret);

        public static bool OssUpload(string localFilename, string picturename)
        {
            try
            {
                ObjectMetadata objectMetadata = new ObjectMetadata
                {
                    ContentType = "image/jpg"
                };
                client.PutObject(bucketName, objectName + picturename, localFilename, objectMetadata);
                return true;
            }
            catch{}
            return false;
        }
    }
}
